<template>
	<view class="container">
		<view class="Telephone">
			<view class="text"><text>房屋名字</text></view>
			<view class="input"><input type="" v-model="name" name="name" placeholder="请输入房屋号" /></view>
		</view>
		<view class="Telephone">
			<view class="text"><text>WiFi名称</text></view>
			<view class="input"><input type="" v-model="ssid" name="ssid" placeholder="请输入WiFi名称" @input="changeDisabled" />
			</view>
		</view>
		<view class="Telephone">
			<view class="text"><text>WiFi密码</text></view>
			<view class="input">
				<input type="text" :password="show" name="password" v-model="password" placeholder="WiFi密码" />
			</view>
			<view class="yanjing">
				<sunui-password @change="showPass" />
			</view>
		</view>
		<view class="Submit">
			<wyb-button class="get" width="90%" @click="submit()" type="filled" :disabled="disabled">保存</wyb-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: "",
				homeId: "",
				ssid: "",
				password: "",
				show: true,
				disabled: true
			}
		},
		onLoad: function(option) { //option为object类型，会序列化上个页面传递的参数
			this.name = option.name;
			this.homeId = option.homeId
			// console.log(this.homeId)
		},
		methods: {
			submit() {
				uni.showLoading({
					title: '正在配网中'
				});
				let message = "";
				try {
					// console.log("dff")
					const configModule = uni.requireNativePlugin("LJY-DeviceConfigModule") //调用android中自定义的插件名称
					// console.log(configModule)
					const ret = configModule.ezModeConection({ //login表示自定义插件的函数名，第一个表示要传递的参数
						homeId: this.homeId,
						ssid: this.ssid,
						password: this.password
					});
					uni.hideLoading(); //加载结束
					message = ret.msg;
				} catch (e) {
					uni.hideLoading(); //加载结束
					message = "无法连接到涂鸦智能平台";
				}
				uni.showModal({
					title: '系统提示',
					content: message,
					showCancel: false,
					complete() {
						uni.navigateBack({
							// url: '/pages/house/equipment/equipment'
							url: '/pages/smartHome/home/equipments'
						})
					}
				});
			},
			changeDisabled(e) {
				if (e.detail.value != "") {
					this.disabled = false;
				} else {
					this.disabled = true;
				}
			},
			showPass(e) {
				this.show = e;
			}
		}
	}
</script>

<style>
	.Telephone {
		display: flex;
		margin-top: 2%;
		background: #FFFFFF;
		width: 100%;
		height: 100rpx;
		text-align: center;
		position: relative;
	}

	.text {
		height: 100rpx;
		width: 30%;
		display: flex;
		justify-content: center;
		line-height: 100rpx;
		justify-content: center;
		line-height: 100rpx;
	}


	.input {
		display: flex;
		align-items: center;
		justify-content: flex-start;
		align-items: center;
		justify-content: flex-start;
		width: 40%;
		height: 100rpx;
		line-height: 100rpx;
		height: 100rpx;
		line-height: 100rpx;
		text-align: left;
	}


	.v-button {
		display: flex;
		align-items: center;
		justify-content: center;
		align-items: center;
		justify-content: center;
		margin: 0;
		padding: 0;
		width: 30%;
		height: 100rpx;
		line-height: 100rpx;
		height: 100rpx;
		line-height: 100rpx;
	}


	.Submit {
		display: flex;
		margin-top: 5%;
		width: 100%;
		height: 100rpx;
		justify-content: center;
		justify-content: center;
	}

	.Telephone>.yanjing {
		line-height: 100rpx;
		position: absolute;
		right: 6%;
	}
</style>
